import React from 'react';
import ImageLazy from '../commons/ImageLazy';
import NavLink from '../commons/NavLink';
import {order_detail} from '../../actions';
import { connect } from 'react-redux';
import Return_btn from '../commons/Return_btn';

const pay_suc = require('!url?limit=8192&name=static/img/[hash:6].[ext]!../../static/img/pay_suc.png');
const pay_fail = require('!url?limit=8192&name=static/img/[hash:6].[ext]!../../static/img/pay_fail.png');

let myDefault = React.createClass({
  componentDidMount:function(){
    const {dispatch} = this.props;
    dispatch(order_detail({union_sn:this.props.unionSN}));
    console.log(this.props.unionSN);
  },
  render:function(){
    console.log(this.props.unionSN);
    return this.props.unionSN == 'fail'?(
      <div className="pay_status">
        <div className="top">
          <ImageLazy src={pay_fail} style={{height:"1rem"}} />
          <h4>支付失败</h4>
        </div>
        <Return_btn />
      </div>
    ):(
      <div className="pay_status">
        {
          this.props.order_detail.map((item,index) => {
            console.log(item.unionSN);
            if(item.unionSN == this.props.unionSN){
              return(
                <div>
                  <div className="top">
                    <ImageLazy src={pay_suc} style={{height:"1rem"}} />
                    <h4>支付成功</h4>
                    <p>
                      为减少您到医院等待时间，请在收到短信提示后，<br/>尽快拨打医生电话预约到院时间。
                    </p>
                  </div>

                  <div className="order_info border_t1">
                    <div className="border_b1">
                      <span>订单编号</span><span>{item.orderSN}</span>
                    </div>
                    <div className="border_b1">
                      <span>创建时间</span><span>{item.createTime}</span>
                    </div>
                    <div className="border_b1">
                      <span>付款时间</span><span>{item.paymentTime}</span>
                    </div>
                  </div>
                </div>
              )
            }
          })
        }
        <Return_btn />
      </div>
    )
  }

})

let mapStateToProps = (state,own)=>{
  var get_order_classify = state.user.get_order_classify,
      user = state.user,
      order_detail = state.user.order_detail;
  return{
    unionSN:own.params.unionSN,
    order_detail
  }
}

export default connect(mapStateToProps)(myDefault)
